//
//  LXHotMusicTableViewCell.m
//  喜马拉雅改良版框架
//
//  Created by liuxin on 15/12/29.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LXHotMusicTableViewCell.h"

@implementation LXHotMusicTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
-(void)setIndex:(NSInteger)index{
    self.indexTemp = index;
    self.num.text = [NSString stringWithFormat:@"%ld",index+1];
}
-(void)createSubViews{
    self.num = [[UILabel alloc]init];
    self.num.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.num];
    [self.num mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(25);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    self.userImage = [[UIImageView alloc]init];
    self.userImage.layer.cornerRadius = 30;
    self.userImage.layer.masksToBounds = YES;
    [self.contentView addSubview:self.userImage];
    [self.userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(60);
        make.width.mas_equalTo(60);
        make.left.equalTo(self.num.mas_right).offset(5);
    }];
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.numberOfLines = 0;
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userImage.mas_right).offset(10);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(20);
        make.top.mas_equalTo(10);
    }];
    
    self.authorLabel = [[UILabel alloc]init];
    self.authorLabel.textColor = [UIColor lightGrayColor];
    self.authorLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.authorLabel];
    [self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
        make.right.mas_equalTo(-20);
        make.left.equalTo(self.userImage.mas_right).offset(10);
        make.height.equalTo(@15);
    }];
}
-(void)setCellModel:(LXHotMusicModel *)cellModel{
    if (self.indexTemp == 0) {
        self.num.textColor = [UIColor colorWithRed:1.000 green:0.241 blue:0.157 alpha:1.000];
    }else if(self.indexTemp == 1){
        self.num.textColor = [UIColor colorWithRed:1.000 green:0.595 blue:0.145 alpha:1.000];
    }else if(self.indexTemp ==2){
        self.num.textColor = [UIColor colorWithRed:0.380 green:1.000 blue:0.326 alpha:1.000];
    }else{
        self.num.textColor = [UIColor blackColor];
    }
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(cellModel.height);
    }];
    [self.userImage sd_setImageWithURL:[NSURL URLWithString:cellModel.coverSmall] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    self.titleLabel.text = cellModel.title;
    self.authorLabel.text = [NSString stringWithFormat:@"by%@",cellModel.nickname];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
